package cn.iocoder.yudao.module.crossborder.inventory.api;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crossborder.inventory.api.dto.InventoryDTO;
import cn.iocoder.yudao.module.crossborder.inventory.api.dto.WarehouseDTO;
import cn.iocoder.yudao.module.crossborder.inventory.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 库存管理 API 接口
 *
 * @author LHL
 */
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
@Tag(name = "RPC 服务 - 库存管理")
public interface InventoryApi {

    String PREFIX = ApiConstants.PREFIX + "/inventory";

    @GetMapping(PREFIX + "/get")
    @Operation(summary = "获得库存记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    CommonResult<InventoryDTO> getInventory(@RequestParam("id") @NotNull Long id);

    @GetMapping(PREFIX + "/list")
    @Operation(summary = "获得库存记录列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    CommonResult<List<InventoryDTO>> getInventoryList(@RequestParam("ids") @NotNull List<Long> ids);

    @PostMapping(PREFIX + "/create")
    @Operation(summary = "创建库存记录")
    CommonResult<Long> createInventory(@RequestBody @Valid InventoryDTO inventory);

    @GetMapping(PREFIX + "/check-stock")
    @Operation(summary = "检查库存")
    @Parameter(name = "productId", description = "商品编号", required = true, example = "1024")
    @Parameter(name = "warehouseId", description = "仓库编号", required = true, example = "2048")
    @Parameter(name = "quantity", description = "数量", required = true, example = "10")
    CommonResult<Boolean> checkStock(@RequestParam("productId") @NotNull Long productId,
                                    @RequestParam("warehouseId") @NotNull Long warehouseId,
                                    @RequestParam("quantity") @NotNull Integer quantity);

    @PostMapping(PREFIX + "/reserve")
    @Operation(summary = "预留库存")
    @Parameter(name = "productId", description = "商品编号", required = true, example = "1024")
    @Parameter(name = "warehouseId", description = "仓库编号", required = true, example = "2048")
    @Parameter(name = "quantity", description = "数量", required = true, example = "10")
    CommonResult<Boolean> reserveStock(@RequestParam("productId") @NotNull Long productId,
                                      @RequestParam("warehouseId") @NotNull Long warehouseId,
                                      @RequestParam("quantity") @NotNull Integer quantity);

    @PostMapping(PREFIX + "/release")
    @Operation(summary = "释放库存")
    @Parameter(name = "productId", description = "商品编号", required = true, example = "1024")
    @Parameter(name = "warehouseId", description = "仓库编号", required = true, example = "2048")
    @Parameter(name = "quantity", description = "数量", required = true, example = "10")
    CommonResult<Boolean> releaseStock(@RequestParam("productId") @NotNull Long productId,
                                      @RequestParam("warehouseId") @NotNull Long warehouseId,
                                      @RequestParam("quantity") @NotNull Integer quantity);

    @GetMapping(PREFIX + "/warehouse/get")
    @Operation(summary = "获得仓库信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    CommonResult<WarehouseDTO> getWarehouse(@RequestParam("id") @NotNull Long id);

}
